package JavaEE.ManyThread1;
import java.util.*;
// 创建线程的方法二: 实现Runnable接口, 重写run方法, 调用start方法启动线程
// 这种写法,将任务写到Runnable中,不涉及到任何和"线程"相关的概念
// 将来如果想把这个任务给别的"主体"来执行,就可以直接把Runnable对象给它.
class myRunnable implements Runnable{
    public void run(){
        while(true){
            System.out.println("hello runnable!");
            try{
                Thread.sleep(999);
            }catch(InterruptedException e){
                e.printStackTrace();
            }
        }
    }
}
public class Demo2 {
    public static void main(String[] args) throws InterruptedException{
        //System.out.println("Hello world!");
        myRunnable runnable = new myRunnable();
        Thread t = new Thread(runnable);
        t.start();
        while(true){
            System.out.println("hello main!");
            Thread.sleep(1000);
        }
    }
}
